home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Science / RLaB / rlib / rank.r < prev    next >
Text File  |  1994-04-25  |  627b  |  27 lines

  1. //-------------------------------------------------------------------//
  2. //
  3. //  Syntax:    rank ( A )
  4. //        rank ( A , tol )
  5.  
  6. //  Description:
  7.  
  8. //  Compute the rank of the matrix A. Rank returns the number of
  9. //  singular values that are larger than max( size(x) ) * norm(x,"2")
  10. //  * eps. 
  11.  
  12. //  If the user specifies tol, the the number of singular values
  13. //  larger than tol is returned.
  14.  
  15. //-------------------------------------------------------------------//
  16.  
  17. rank = function(x, tol)
  18. {
  19.   local(s);
  20.   s = svd(x);
  21.   if (!exist (tol))
  22.     { 
  23.       tol = max(size(x)) * norm(x,"2") * epsilon();
  24.     }
  25.   return sum(s.sigma > tol);
  26. };
  27.